<template>
  <div v-if="isShowSubComp" class="warp">
    <weather-info-comp
      :nest-id="nestId"
      :weather-info="nestSocketInfo.weather"
      @closeNestComp="closeNestComp"
    />

    <!-- 切换ai视频 -->
    <div
      class="AIVideoBtn"
      :class="{ selectAI: ifAIVideo }"
      @click="AIVideoChange"
      v-if="false"
    >
      AI流
    </div>

    <!-- 指南针 -->
    <div class="northbtn" @click="cameraTypeChange">
      <div v-show="cameraType == 1" class="cameraType1">
        <svg-icon
          icon-class="north"
          :style="{ transform: 'rotate(' + deg + 'deg)' }"
        />
      </div>
      <div v-show="cameraType == 2" class="cameraType2">
        <svg-icon icon-class="navigationfly2" />
      </div>
      <div v-show="cameraType == 3" class="cameraType3">
        <svg-icon icon-class="airpath" />
      </div>
    </div>
    <nest-info-comp
      ref="nest_info"
      :nest="nestInfo"
      :title="nestInfo.nest_name"
      :nest-info="nestSocketInfo"
      :mission-info="missionSocketInfo"
      :aircraft-info="aircraftSocketInfo"
    />
    <aircraft-info-comp
      ref="aircraft_info"
      :nest-id="nestId"
      :title="nestInfo.flight_aircraft.aircraft_type"
      :nest-info="nestSocketInfo"
      :nestHeight="nestInfo.position.altitude"
      :nestlatitude="nestInfo.position.latitude"
      :nestlongitude="nestInfo.position.longitude"
      :aircraft-info="aircraftSocketInfo"
    />

    <aircraft-video-action-bar
      v-if="showActionBar"
      :is-show-aircraft-comp="isShowAircraft"
      :full-screen-comp="fullScreenComp"
      :nest-info="nestInfo"
      :is-sharing="isSharing"
      :aircraftSocketInfo="aircraftSocketInfo"
      :share-url="shareUrl"
      :record-id="record_code"
      @refreshVideo="refreshVideo"
      @setVideoRes="setVideoRes"
      @showShareCard="showShareCard"
      @closeShare="closeShareVideo"
    />
    <aircraft-video-share-card
      v-if="true"
      ref="ref_video_share_card"
      :is-show-aircraft-comp="isShowAircraft"
      :nest-info="nestInfo"
      :share-url="shareUrl"
      :share-img="shareImg"
      :dead-line="deadLine"
    />

    <nest-video-inside-comp
      v-if="nestInfo.nest_type_id === 2"
      :full-screen-comp="fullScreenComp"
      :live-url="nestInfo.inner_video_url"
      :title="nestInfo.nest_name"
      :is-show-aircraft-comp="isShowAircraft"
      :nestInfo="nestInfo"
    />
    <nest-video-comp
      v-if="nestInfo.nest_type_id != 19"
      :full-screen-comp="fullScreenComp"
      :live-url="nestInfo.nest_video_url"
      :title="nestInfo.nest_name"
      :is-show-aircraft-comp="isShowAircraft"
      :nestInfo="nestInfo"
    />
    <aircraft-video-comp
      ref="ref_aircraftVideo"
      :full-screen-comp="fullScreenComp"
      :live-url="
        ifAIVideo
          ? nestInfo.flight_aircraft.aircraft_ai_url
          : nestInfo.flight_aircraft.aircraft_video_url
      "
      :title="nestInfo.flight_aircraft.aircraft_type"
      :is-show-aircraft-comp="isShowAircraft"
      :nest-info="nestInfo"
    />
    <bottom-nest-menu :nest-code="nest_code" />
  </div>
</template>

<script>
import NestVideoInsideComp from "@/views/components/NestAndAircraftSubComps/nestVideoInsideComp";
import NestVideoComp from "@/views/components/NestAndAircraftSubComps/nestVideoComp";
import AircraftVideoComp from "@/views/components/NestAndAircraftSubComps/aircraftVideoComp";
import WeatherInfoComp from "@/views/components/NestAndAircraftSubComps/weatherInfoComp";
import NestInfoComp from "@/views/components/NestAndAircraftSubComps/nestInfoComp";
import AircraftInfoComp from "@/views/components/NestAndAircraftSubComps/aircraftInfoComp";
import BottomNestMenu from "@/views/components/NestAndAircraftSubComps/BottonNestMenu.vue";
import AircraftVideoActionBar from "@/views/components/NestAndAircraftSubComps/aircraftVideoActionBar";
import AircraftVideoShareCard from "@/views/components/NestAndAircraftSubComps/aircraftVideoShareCard";
import {
  closeShareVideo,
  getFlyingInfo,
  getShareVideoInfo,
} from "@/api/flycontrol";

let aircraftDataSource = null; // 飞机图层
let flyAirlineDataSource = null; // 航线和轨迹图层
var airlinePath = null;
var curAirline = null;
var MyPlane = null;
//Set up chase camera
var matrix3Scratch = new Cesium.Matrix3();
var positionScratch = new Cesium.Cartesian3();
var orientationScratch = new Cesium.Quaternion();
var ModelListener = null;

function getModelMatrix(entity, time, result) {
  var position = Cesium.Property.getValueOrUndefined(
    entity.position,
    time,
    positionScratch
  );
  if (!Cesium.defined(position)) {
    return undefined;
  }
  var orientation = Cesium.Property.getValueOrUndefined(
    entity.orientation,
    time,
    orientationScratch
  );
  if (!Cesium.defined(orientation)) {
    result = Cesium.Transforms.eastNorthUpToFixedFrame(
      position,
      undefined,
      result
    );
  } else {
    result = Cesium.Matrix4.fromRotationTranslation(
      Cesium.Matrix3.fromQuaternion(orientation, matrix3Scratch),
      position,
      result
    );
  }
  return result;
}

export default {
  name: "NestAndAircraftComp",
  components: {
    AircraftVideoActionBar,
    AircraftVideoShareCard,
    BottomNestMenu,
    NestVideoInsideComp,
    NestVideoComp,
    AircraftVideoComp,
    WeatherInfoComp,
    NestInfoComp,
    AircraftInfoComp,
  },
  props: {
    isShow: {
      type: Boolean,
      default: () => false,
    },
    fullScreenComp: {
      type: Number,
      default: () => 0,
    },
    nestId: {
      type: String,
      default: () => "",
    },
  },
  data() {
    return {
      isShowSubComp: false,
      // nestInfo { nest_code:"62ecd5ec-f611-4dc8-8668-b774c1c0863d"   nest_name: "衢江06-莲花镇-亚轩宾馆"}
      nestInfo: {
        aircraftLiveUrl: "",
        nest_video_url: "",
        inner_video_url: "",
        flight_aircraft: {
          aircraft_video_url: "",
          aircraft_type: "",
        },
      },
      nestName: "查找中...",
      aircraftSocketInfo: {},
      isShowAircraftComp: true,
      nestSocketInfo: {},
      missionSocketInfo: {},
      isShowNestComp: false,
      socket: undefined,
      isShowAircraft: true,
      waypoints: null,
      aircraftPath: [],
      aircraftPositions: [],
      cameraType: 1,
      deg: 0,
      nest_code: "",

      ifAIVideo: false, // 无人机视频流 AI
      //
      shareUrl: "",
      shareImg: "",
      deadLine: 0,
      isSharing: false,
      record_code: "",
      showActionBar: false,
    };
  },
  watch: {
    fullScreenComp(newVal, oldVal) {
      if (newVal != 2) {
        this.ifAIVideo = false;
      }
      if (newVal !== 2) {
        this.$refs.ref_video_share_card &&
          this.$refs.ref_video_share_card.closeShareForm();
      }
      this.$emit("update:fullScreenComp", this.fullScreenComp);
    },
    nestInfo() {
      this.sharing = false;
      this.isSharing = false;
      // this.$refs.ref_video_share_card.closeShare()
    },
  },
  created() {
    this.nest_code = this.nestId;
  },
  mounted() {
    this.clearState();
    this.initSocket();
    this.initMap();
    this.setNestInfo();
    this.initBusEvent();
    this.resetVideoPosition(true);
  },
  beforeDestroy() {
    this.destroyMap();
    this.$bus.emit("EarthResetView", "");
    // 打开机巢问题图层
    this.$bus.emit("toggleIssueLayer", true);
    this.$bus.emit("bottomButtonShow", true);

    // 清楚cesium相机监听事件
    viewer.scene.preRender.removeEventListener(ModelListener);
  },
  methods: {
    cameraTypeChange() {
      if (this.cameraType == 3) {
        var type = 1;
      } else {
        var type = this.cameraType + 1;
      }
      switch (type) {
        case 1:
          viewer.trackedEntity = undefined;
          // 禁止旋转相机
          viewer.scene.screenSpaceCameraController.enableRotate = true;
          // 禁止平移地图
          viewer.scene.screenSpaceCameraController.enableTranslate = true;
          if (curAirline) {
            viewer.flyTo(curAirline);
          } else {
            CesiumUtil.FlyToElementByGPS({
              longitude: this.nestInfo.position.longitude,
              latitude: this.nestInfo.position.latitude,
              height: this.nestInfo.position.altitude,
              distance: 500,
            });
          }

          this.cameraType = type;
          break;
        case 2:
          if (MyPlane) {
            this.cameraType = type;
            console.log(MyPlane);
            viewer.trackedEntity = MyPlane.model;
          }
          break;
        case 3:
          if (curAirline) {
            this.cameraType = type;
            console.log(curAirline);
            viewer.trackedEntity = undefined;
            viewer.zoomTo(
              curAirline,
              new Cesium.HeadingPitchRange(0, Cesium.Math.toRadians(-90))
            );
            // 禁止旋转相机
            viewer.scene.screenSpaceCameraController.enableRotate = false;
            // 禁止平移地图
            viewer.scene.screenSpaceCameraController.enableTranslate = false;
          } else {
            viewer.trackedEntity = undefined;
            // 禁止旋转相机
            viewer.scene.screenSpaceCameraController.enableRotate = true;
            // 禁止平移地图
            viewer.scene.screenSpaceCameraController.enableTranslate = true;
            CesiumUtil.FlyToElementByGPS({
              longitude: this.nestInfo.position.longitude,
              latitude: this.nestInfo.position.latitude,
              height: this.nestInfo.position.altitude,
              distance: 500,
            });
            this.cameraType = 1;
          }
          break;
        default:
          break;
      }
    },
    initBusEvent() {
      // 关闭机巢问题图层
      this.$bus.emit("toggleIssueLayer", false);
      this.$bus.on("doubleClick", () => {
        console.log("doubleClick NestAndA");
        const state =
          this.$refs.nest_info.getVisibleState() &&
          this.$refs.aircraft_info.getVisibleState();
        this.$bus.emit("showNestComp", !state);
        this.$bus.emit("showAircraftComp", !state);
        this.isShowAircraft = !state;
        // if (true) {
        //   this.$bus.emit('showNestComp', true)
        //   this.$bus.emit('showAircraftComp', true)
        // } else {
        //   this.$bus.emit('showNestComp', false)
        //   this.$bus.emit('showAircraftComp', false)
        // }
      });
      this.$bus.on("changeNest", (nestId) => {
        this.nest_code = nestId;
        this.destroyMap();
        this.releaseShareCard();
        this.initMap();
        this.$refs.aircraft_info?.setDefaultData();
        this.$refs.nest_info?.setDefaultData();

        this.initSocket();
        this.setNestInfo();
      });
    },
    resetVideoPosition(isShowAircraft) {
      // this.$message(isShowAircraft + '')
      this.isShowAircraft = isShowAircraft;
      this.$parent.resetVideoPosition(isShowAircraft);
    },
    setNestInfo() {
      // 获取存储信息 nestId  和 nestList
      // this.$message.success(this.nestId)
      const nestList = this.$store.getters.nestList;
      this.nestInfo = nestList.filter((item) => {
        return item.nest_code === this.nest_code;
      })[0];
      console.log("nestInfo", this.nestInfo);
      // 过滤出nestInfo
      // for (const value of values(nestList)) {
      //   this.nestInfo = value.list.filter(item => {
      //     return item.nest_code === this.nestId
      //   })[0]
      //   if (this.nestInfo) break
      // }
      // 显示子控件和错误提示
      if (this.nestInfo.nest_name) {
        this.nestName = this.nestInfo.nest_name;
        // 添加数据
        // this.nestInfo.nestLiveUrl = 'http://221.12.137.237:8000/live/outside_1660a4fb-ce58-4729-b6c8-c1ea21d22c1d.flv'
        // this.nestInfo.aircraftLiveUrl = 'http://221.12.137.237:8000/live/outside_1660a4fb-ce58-4729-b6c8-c1ea21d22c1d.flv'
        // debug
        // this.$message.success('查找机巢' + this.nestInfo.nest_name)
        this.isShowSubComp = true;
        const _this = this;
        console.log("测试数据1", _this.nestInfo.position);
        CesiumUtil.FlyToElementByGPS({
          longitude: _this.nestInfo.position.longitude,
          latitude: _this.nestInfo.position.latitude,
          height: _this.nestInfo.position.altitude,
          // longitude: 118.459463,
          // latitude: 28.930728,
          // height: 134.24,
          distance: 3000,
        });
      } else {
        this.$message.error("查找机巢(" + this.nest_code + ")失败");
      }
    },
    // 清除地图图层状态
    clearState() {
      // this.$bus.emit("changeModule", 4); // 右侧组件初始化为‘预警信息’
      this.$parent.$refs.rightKanBan.changeModule(4);
      this.$bus.emit("ClearView3Map"); // 清空航线排期的地图
      this.$bus.emit("clearQj"); // 清除全景图层
    },
    // 飞机和机巢实时信息
    initSocket() {
      console.log("NestAndAircraftComp initSocket");
      const that = this;
      if (KBSocket?.connected) {
        KBSocket.io.emit("changeTarget", {
          targets: [that.nest_code],
        });
        this.showActionBar = true;
        return false;
      }
      this.showActionBar = true;
      KBSocket.io.emit("registerListener", {
        topics: ["record_mission", "aircraft_info", "nest_info"],
        targets: [that.nest_code],
      });

      // 监听返回数据
      KBSocket.io.on("record_mission", function (res) {
        console.log("record_mission");
        if (res.nest_code !== that.nest_code) {
          return false;
        }
        // 飞行任务
        if (res?.flight_record_code) {
          if (res?.flight_record_code === that.record_code) {
            if (that.missionSocketInfo?.flight_record_code) {
              // 更新实时数据
              that.updateMissionInfo(res);
            } else {
              that.initMissionInfo();
            }
          } else {
            that.initMissionInfo();
          }
          that.record_code = res?.flight_record_code || "";
        } else {
          // 是否处理
          // that.missionSocketInfo = {}
        }
      });
      // 飞行中信息
      KBSocket.io.on("aircraft_info", function (res) {
        if (res.nest_code !== that.nest_code) {
          return false;
        }
        console.log("sockett2", res);
        // 飞行中信息
        that.aircraftSocketInfo = res;
        // 绘制飞机位置
        that.drawAircraftOnMap();
      });
      // 机巢信息
      KBSocket.io.on("nest_info", function (res) {
        if (res.nest_code !== that.nest_code) {
          return false;
        }
        // 机槽信息
        if (res instanceof Object) that.nestSocketInfo = res;
        // that.isShowNestComp = true
      });
      //
      // client-side
    },
    async initMissionInfo() {
      const res = await getFlyingInfo({ nest_code: this.nest_code });
      if (res && res.msg === "ok") {
        this.missionSocketInfo = res.data;
        this.drawAirlineOnMap(res.data);
      }
    },
    updateMissionInfo(data) {
      this.missionSocketInfo.percent_new = data.percent_new;
      this.missionSocketInfo.current_state = data.current_state;
      this.missionSocketInfo.photo_count = data.photo_count;
      this.missionSocketInfo.nest_code = data.nest_code;
      this.missionSocketInfo = JSON.parse(
        JSON.stringify(this.missionSocketInfo)
      );
    },
    /**
     *  绘制飞机位置
     */
    drawAircraftOnMap() {
      if (
        this.aircraftSocketInfo &&
        this.aircraftSocketInfo.isAircraftConnected &&
        this.aircraftSocketInfo.aircraftLocationLongitude &&
        this.aircraftSocketInfo.aircraftLocationLatitude
      ) {
        var h =
          this.aircraftSocketInfo.aircraftAltitude +
          this.nestInfo.position.altitude +
          2;
        // 飞机绘制
        var p = Cesium.Cartesian3.fromDegrees(
          this.aircraftSocketInfo.aircraftLocationLongitude,
          this.aircraftSocketInfo.aircraftLocationLatitude,
          h
        );

        var head =
          this.aircraftSocketInfo?.aircraftYaw < 0
            ? this.aircraftSocketInfo.aircraftYaw + 360
            : this.aircraftSocketInfo.aircraftYaw;
        if (!head) {
          head = 0;
        }
        var heading = Cesium.Math.toRadians(head + 180);

        var hpr = new Cesium.HeadingPitchRoll(heading, 0, 0); // 3.14159
        var orientation = Cesium.Transforms.headingPitchRollQuaternion(p, hpr);
        if (aircraftDataSource) {
          if (!Cesium.defined(MyPlane)) {
            var m = {
              position: p,
              orientation: orientation,
            };
            MyPlane = new CesiumUtil.PlaneModel(m, aircraftDataSource);
          } else {
            MyPlane.update(p, orientation);
          }
          aircraftDataSource.show = true;
        }

        // 路径绘制
        if (this.aircraftPath.length > 1) {
          if (Cesium.defined(airlinePath)) {
            this.aircraftPositions.push(p);
          }
        }
      } else {
        if (MyPlane) {
          MyPlane.remove();
          MyPlane = null;
        }
      }
    },
    getPath() {
      var arr = [];
      for (var i = 0; i < this.aircraftPath.length; i++) {
        arr.push(
          this.aircraftPath[i].longitude,
          this.aircraftPath[i].latitude,
          this.aircraftPath[i].height
        );
      }
      return Cesium.Cartesian3.fromDegreesArrayHeights(arr);
    },
    formatWaypoints(obj) {
      if (obj?.lineListInfo[0]?.linePointsList?.length > 0) {
        //
        obj.linePointsList = [];
        obj.lineListInfo[0].linePointsList.forEach((waypoint) => {
          obj.linePointsList.push(waypoint);
        });
      }
    },
    drawAirlineOnMap(data) {
      // 航线
      if (!flyAirlineDataSource) {
        return false;
      }
      if (data?.waypoints) {
        if (flyAirlineDataSource.entities.values.length === 0) {
          const obj = data.waypoints;
          this.formatWaypoints(obj);
          let pointArr = [];
          let positions = [];
          // todo delete
          // if (obj['mapConfigs']) {
          //   if (obj['mode'] === 'ORTHOPHOTO') {
          //     positions = obj['mapConfigs']['points'][0]
          //   } else {
          //     positions = obj['mapConfigs']['points']
          //   }
          //   for (var j = 0; j < positions.length; j++) {
          //     if (positions[j]['location']) {
          //       pointArr.push(
          //         positions[j]['location']['lng'],
          //         positions[j]['location']['lat'],
          //         positions[j]['location']['alt'] + this.nestInfo.position.altitude + 2
          //       )
          //     } else if (positions[j]['wayPointLongitude']) {
          //       pointArr.push(
          //         positions[j]['wayPointLongitude'],
          //         positions[j]['wayPointLatitude'],
          //         100 + this.nestInfo.position.altitude
          //       )
          //     }
          //   }
          // } else
          if (obj["linePointsList"]) {
            positions = obj["linePointsList"];
            if (!positions || positions.length === 0) {
              return false;
            }
            if (positions.length === 1) {
              pointArr = [
                this.nestInfo.position.longitude,
                this.nestInfo.position.latitude,
                this.nestInfo.position.altitude + positions[0]["location"][2],
                positions[0]["location"][1],
                positions[0]["location"][0],
                positions[0]["location"][2] + this.nestInfo.position.altitude,
              ];
            } else {
              for (let i = 0; i < positions.length; i++) {
                pointArr.push(
                  positions[i]["location"][1],
                  positions[i]["location"][0],
                  positions[i]["location"][2] + this.nestInfo.position.altitude
                );
              }
            }
          }
          var line = {
            type: "airline",
            positions: pointArr,
            color: "rgba(0,255,255,0.9)",
            isheight: true,
          };
          if (pointArr.length > 3) {
            curAirline = CesiumUtil.AddLine(line, flyAirlineDataSource);
            flyAirlineDataSource.show = true;
          }
        }
      } else {
        curAirline = null;
        if (flyAirlineDataSource) {
          flyAirlineDataSource.entities.removeAll();
        }
        if (airlinePath) {
          airlinePath.remove();
          airlinePath = null;
        }

        this.aircraftPath = [];
        this.aircraftPositions = [];
      }
      // 轨迹
      console.log("飞行数据2", this.aircraftPath.length);
      if (data?.position && this.aircraftPath.length === 0) {
        console.log("取到历史轨迹");
        var that = this;
        data.position.forEach(function (value, index) {
          if (value.longitude != 0 && value.latitude != 0) {
            that.aircraftPath.push({
              longitude: value.longitude || value[0],
              latitude: value.latitude || value[1],
              height:
                parseInt(value.height || value[2]) +
                that.nestInfo.position.altitude,
            });
          }
        });
      }
      //
      if (!Cesium.defined(airlinePath)) {
        this.aircraftPositions = this.getPath();
        if (this.aircraftPositions.length > 0) {
          console.log("绘制历史轨迹", this.aircraftPositions);
          airlinePath = new CesiumUtil.PathPrimitive(
            this.aircraftPositions,
            flyAirlineDataSource
          );
          flyAirlineDataSource.show = true;
        }
      }
    },
    initMap() {
      if (!aircraftDataSource) {
        aircraftDataSource = CesiumUtil.CreateLayer("aircraftDataSource");
        aircraftDataSource.show = false;
      }
      aircraftDataSource.entities.removeAll();
      if (!flyAirlineDataSource) {
        flyAirlineDataSource = CesiumUtil.CreateLayer("flyAirlineDataSource");
        flyAirlineDataSource.show = false;
      }
      flyAirlineDataSource.entities.removeAll();

      var scratch = new Cesium.Matrix4();
      var camera = viewer.scene.camera;
      const heading = Cesium.Math.toRadians(180.0);
      const pitch = Cesium.Math.toRadians(-45.0);
      const range = 800.0;
      var that = this;
      ModelListener = function () {
        if (that.cameraType == 2 && MyPlane) {
          // var ppp = Cesium.Math.toRadians(that.aircraftSocketInfo.gimbalPitch)
          getModelMatrix(MyPlane.model, viewer.clock.currentTime, scratch);
          camera.lookAtTransform(
            scratch,
            new Cesium.HeadingPitchRange(heading, pitch, range)
          );
        } else if (that.cameraType == 1) {
          var heading1 = viewer.scene.camera.heading;
          var x = -Cesium.Math.toDegrees(heading1);
          that.deg = x;
        }
      };
      viewer.scene.preRender.addEventListener(ModelListener);
    },
    destroyMap() {
      if (MyPlane) {
        MyPlane.remove();
        MyPlane = null;
      }
      if (aircraftDataSource) {
        aircraftDataSource.entities.removeAll();
        aircraftDataSource.show = false;
        aircraftDataSource = null;
      }
      if (flyAirlineDataSource) {
        flyAirlineDataSource.entities.removeAll();
        flyAirlineDataSource.show = false;
        flyAirlineDataSource = null;
      }

      if (airlinePath) {
        airlinePath.remove();
        airlinePath = null;
      }

      this.aircraftPath = [];
      this.aircraftPositions = [];
    },
    closeNestComp() {
      console.log("关闭nest");
      this.destroyMap();
      this.$emit("closeNest");
    },
    /**
     *  飞机视频操作： 设置分辨率，刷新，分享
     */
    refreshVideo() {
      console.log("refresh12082");
      this.$refs.ref_aircraftVideo.refreshComp();
    },
    setVideoRes() {},
    getSharePath() {
      console.log("getSharePath", window.location.href);
      console.log("getSharePath", window.location.hostname);
      // http://192.168.10.53:9529/alpha/front/#/sharedVideo
      // return 'abc'
      // return window.location.href + 'sharedVideo?recordId=' + 'a6d69ee9-cec5-43e2-812d-653c7346d529'
      return window.location.href + "sharedVideo?recordId=" + this.record_code;
    },
    releaseShareCard() {
      this.$refs.ref_video_share_card &&
        this.$refs.ref_video_share_card.closeShareForm();
      this.showActionBar = false;
    },
    async showShareCard() {
      if (!this.record_code) {
        this.$message.info("直播还未开始");
        // return
      }
      //
      if (this.isSharing) {
        this.$refs.ref_video_share_card.showShareForm();
        return;
      }
      //
      const params = {
        url: this.getSharePath(),
        record_id: this.record_code,
        // record_id: 'a6d69ee9-cec5-43e2-812d-653c7346d529'
      };
      const res1 = await getShareVideoInfo(params);
      if (res1 && res1.msg === "ok") {
        this.shareUrl = res1.data.url;
        this.shareImg = res1.data.img;
        this.deadLine = res1.data.expire;
        this.$refs.ref_video_share_card.showShareForm();
        this.isSharing = true;
        this.$message.success("已开启视频分享");
      } else {
        this.$message(res1.msg ? res1.msg : "分享失败请稍后重试!");
      }
    },
    //
    async closeShareVideo() {
      //
      if (!this.isSharing) {
        this.$refs.ref_video_share_card.closeShare();
        return;
      }
      //
      const res3 = await closeShareVideo({
        url: this.shareUrl,
        record_id: this.record_code,
      });
      if (res3 && res3.error_code === 0) {
        this.$refs.ref_video_share_card.closeShare();
        this.$message.success("已关闭视频分享");
        this.isSharing = false;
      } else {
        this.$message("已关失败，请稍后重试");
      }
    },

    // ai 视频流切换
    AIVideoChange() {
      console.log("nestInfo", this.nestInfo.flight_aircraft);
      this.ifAIVideo = !this.ifAIVideo;
    },
  },
};
</script>

<style lang="scss" scoped>
.warp {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;

  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: 1;
  margin: 0;
  padding: 0;
}

.AIVideoBtn {
  pointer-events: auto;
  position: absolute;
  top: 95px;
  left: vw(400);
  color: #ddd9d9;
  background-color: #cccccc40;
  border: 1px solid #c1bebe;
  border-radius: 4px;
  z-index: 9;
  box-shadow: 0 0 4px 2px rgba(140, 138, 138, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px 15px;
  cursor: pointer;

  &:hover {
    background-color: #cccccc60;
  }

  &.selectAI {
    background-color: #72add55e;
    color: #1cc1ff;
    border: 1px solid #1cc1ff;
    box-shadow: 0 0 4px 2px rgba(124, 207, 231, 0.5);
  }
}

.northbtn {
  position: absolute;
  top: 80px;
  right: vw(400);
  width: 60px;
  height: 60px;
  z-index: 9;
  background-color: white;
  opacity: 0.5;
  font-size: 40px;
  line-height: 60px;
  border-radius: 30px;
  text-align: center;
  color: black;
  pointer-events: initial;
  cursor: pointer;
  overflow: hidden;

  &:hover {
    opacity: 1;
  }

  .cameraType2 {
    background-color: #333333;
    color: #ffffff;
  }
}
</style>
